﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace APIBetaSeries.Models.Member
{
    public class Member : ObjetBase
    {
        public String Token { get; set; }
        public String Login { get; set; }
        public String Cached { get; set; }
        public String Avatar { get; set; }
        public StatsMember StatsMember{get; set; }

        public Member(XDocument value)
            : base(value)
        {
            if (value != null)
            {
                XElement xRoot = value.Element("root");
                if (xRoot != null)
                {
                    XElement xMember = xRoot.Element("member");
                    if (xMember != null)
                    {
                        XElement xLogin = xMember.Element("login");
                        if (xLogin != null) Login = xLogin.Value;
                        XElement xToken = xMember.Element("token");
                        if (xToken != null) Token = xToken.Value;
                        XElement xCached = xMember.Element("cached");
                        if (xCached != null) Cached = xCached.Value;
                        XElement xAvatar = xMember.Element("avatar");
                        if (xAvatar != null) Avatar = xAvatar.Value;
                        XElement xStats = xMember.Element("stats");
                        if (xStats != null)
                        {
                            StatsMember = new StatsMember();
                            XElement xShows = xStats.Element("shows");
                            if (xShows != null) StatsMember.NbShowFollowed = Convert.ToInt64(xShows.Value);
                            XElement xSeasons = xStats.Element("seasons");
                            if (xSeasons != null) StatsMember.NbSeasons = Convert.ToInt64(xSeasons.Value);
                            XElement xEpisodes = xStats.Element("episodes");
                            if (xEpisodes != null) StatsMember.NbEpisodes = Convert.ToInt64(xEpisodes.Value);
                            //TODO: AM - Continuer stats
                        }
                    }
                }
            }
        }
    }
}
